public class demo31 {
    public boolean canConstruct(String ran, String mag) {
        if(ran.length()>mag.length()) return false;
        if(ran.length() == 0) return true;
        int[] word = new int[26];
        char[] c1 = ran.toCharArray();
        char[] c2 = mag.toCharArray();

        //计数
        //统计ran中的字符出现次数
        for(int i = 0;i<c1.length;i++)
        {
            word[c1[i]-'a']++;
        }
        //统计mag与ran相同的字符
        int k = 0;
        for(int j = 0;j<c2.length;j++)
        {
            if(c2[j] == c1[k]){
                word[c2[j]-'a']--;
                k++;
            }
            else if(k == (c1.length-1)) return true;
            else{
                ;
            }
        }
        for(int val : word)
            if(val!=0) return false;
        return true;
    }

    public static void main(String[] args) {
        demo31 d1 = new demo31();
        d1.canConstruct("abcd","abcdef");
    }
}
